<?php
    session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oid = $_REQUEST['oid'];
    $usuario = $_SESSION['usuario'];
    $pq = $_REQUEST['pq'];
    $descri = $_REQUEST['descri'];
    
    if($usuario == ""){
            print_r(json_encode(array('n'=>1)));
   }else{
       $count = "select count(*)as n from segtranslado where hcnsolexa='".$oid."'";
       $res = $con->query($count);
       
        while($res2 = mssql_fetch_array($res)){
         $n = $res2['n'];
        } 
        if($n == 0){
            $insert = "insert into segtranslado (hcnsolexa,traisladosi,trtipoaislami,trfechapoais,usu_oidpoais,trrazonaisla)
                       values('".$oid."','1','".$pq."',GETDATE(),'".$_SESSION['usuario']."','".$descri."')";
            $con->query($insert);
            
        }else{
            $update = "update segtranslado
                        set traisladosi = '1',
                        trtipoaislami = '".$pq."',
                        trfechapoais = GETDATE(),
                        usu_oidpoais = '".$_SESSION['usuario']."',
                        traisladono = '',
                        trfechano = '',
                        usu_oidno = '',
                        trrazonaisla = '".$descri."'
                       where hcnsolexa = '".$oid."'";
            $con->query($update);
        }
        print_r(json_encode(array('n'=>2,'pq'=>$pq)));
   } 
   
   $Existe = "select count(*) as E from segimagenes where hcnsolexa = '".$oid."'";
   $resp = $con ->query($Existe);
   
   while($resp2 = mssql_fetch_array($resp)){
       $E = $resp2['E'];
   }
   if($E == 0){
       $insertar = "insert into segimagenes (hcnsolexa,solcita,fecsolcita,usu_oidsc)values('".$oid."','1',GETDATE(),'".$_SESSION['usuario']."')";
       $con ->query($insertar);
   }else{
       $Editar = "update segimagenes
                  seg solcita =  '1',
                  fecsolcita = GETDATE(),
                  usu_oidsc = ''
                  where hcnsolexa = '".$oid."'";
       $con ->query($Editar);
   }
    $con->cerrarConexion();
    
 
?>